package banking;

import money.Currencies;
import money.Money;
import conditions.*;
import java.util.ArrayList;
import java.util.Currency;
import java.util.List;
import java.util.Locale;

public abstract class Account {

	// -------------------------------------
	// Attributes
	// -------------------------------------

	private int accountNumber;
	private String accountHolder;
	private String language;
	private String country;
	private Money balance = new Money(0);

	private List<Statement> BookList = new ArrayList<Statement>();
	DepositConditions depcon = new DepositConditions();
	GiroConditions girocon = new GiroConditions();
	
	
	// -------------------------------------
	// Constructors
	// -------------------------------------

	protected Account(int accountNumber, String accountHolder, String typ,
			String language, String country) {
		this.accountHolder = accountHolder;
		this.language = language;
		this.country = country;
		this.accountNumber = accountNumber;
		

	}

	// -------------------------------------
	// Methods
	// -------------------------------------

	public void outpoutAccountValue() {
		System.out.println("Account balance: "
				+ (((double) balance.getValue()) / 100));
		System.out.println(accountNumber);
		int counter = 0;
		if(getBookList().get(counter) != null){
			System.out.println(getBookList().get(counter));
			counter++;
		}
	}

	public String showOutput() {
		Currency currency = Currency.getInstance(new Locale(getLanguage(), getCountry()));
		return 
		(changeToCurrency(balance.getValue() ,
				accountNumber))
		+ currency.getSymbol();
	}
	
	public long changeToEuro(long value, int accountNumber) {
		
		Currency ccurrency = Currency.getInstance(new Locale(
				getLanguage(),
				getCountry()));
		if (!ccurrency.getCurrencyCode().matches("EUR")) {
			long exchangeValue = Currencies.CurrenciesValue.valueOf(
					ccurrency.getCurrencyCode()).getCurrenciesValue();
			value = ((value * 10000) / (exchangeValue * 100)) + 1;
		}
		return value;
	}

	public long changeToCurrency(long value, int accountNumber) {
		
		Currency ccurrency = Currency.getInstance(new Locale(
				getLanguage(), getCountry()));
		if (!ccurrency.getCurrencyCode().matches("EUR")) {
			long exchangeValue = Currencies.CurrenciesValue.valueOf(
				ccurrency.getCurrencyCode()).getCurrenciesValue();
			value = ((value) * exchangeValue * 100) / 10000;
		}

		return value;
	}

	// ---------------------------------------
	// Abstract Methods
	// ---------------------------------------

	public abstract void setInterestValue(int changeInterestValue);

	public abstract void setRuntimeValue(int length);

	public abstract void setTimestamp(long timestamp);

	public abstract long getTimestamp();

	public abstract void interest();

	public abstract void minus(Money lInput);

	public abstract void plus(Money lInput);

	// ########################################
	// Getter / Setter
	// ########################################
	
	public void setBalance(long newbalance) {
		balance.setValue(newbalance);
	}

	public int getAccountNumber() {
		return accountNumber;
	}

	public void setAccountNumber(int newAccountNumber) {
		accountNumber = newAccountNumber;
	}
	
	public String getLanguage() {
		return language;
	}

	public String getCountry() {
		return country;
	}

	public void setBalance(Money balance) {
		this.balance = balance;
	}

	public Money getBalance() {
		return balance;
	}
	
	public String getAccountHolder(){
		return accountHolder;
	}

	public List<Statement> getBookList() {
		return BookList;
	}
}
